package com.grand.ch07;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class TryWithResourceTexst {
    public static void main(String[] args) {
        System.out.println("111");
    }

    // 没有使用try-with-resource方法
    public static void noTryWith(){
        try{
            FileInputStream inputStream = new FileInputStream(new File("test"));
            Throwable var2 = null;
            try{
                System.out.println(inputStream.read());
            }catch(Exception var12){
                var2 = var12;
                throw var12;
            }finally {
                if(inputStream !=null){
                    if(var2 != null){
                        try{
                            inputStream.close();
                        }catch (Throwable var11){
                            var2.addSuppressed(var11);
                        }
                    }else{
                        inputStream.close();
                    }
                }
            }
        }catch(Exception var14){
            throw new RuntimeException(var14.getMessage(),var14);
        }
    }

    public static void tryWith(){
        try(FileInputStream input = new FileInputStream(new File("test"))){
            System.out.println(input.read());
        }catch (IOException e){
            throw new RuntimeException(e.getMessage(),e);
        }
    }
}
